package com.cooler.floatview;

import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.util.Log;

public class CameraHardware
{
	private static final String TAG = "Vtag";
	
	public static boolean checkCameraHardware(Context contex) {
		if (contex.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
			return true;
		}
		
		return false;
	}
	
	public static int getNumber() {
		return Camera.getNumberOfCameras();
	}
	
	public static Camera openCamera() {
		Camera camera = null;
		
		try {
			camera = Camera.open();
		} catch (Exception e) {
			e.printStackTrace();
			Log.d(TAG, "fail to open camera: " + e);
		}
		
		return camera;
	}
	
	public static Camera openCamera(int cameraId) {
		Camera camera = null;
		
		try {
			camera = Camera.open(cameraId);
		} catch (Exception e) {
			e.printStackTrace();
			Log.d(TAG, "fail to open camera " + cameraId + ": " + e);
		}
		
		return camera;
	}
}
